package com.my.mall.manage.order.service.orderInfo;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.my.mall.manage.order.dao.orderInfo.OrderInfoManageDao;
import com.my.mall.manage.order.dto.orderInfo.OrderInfoManageDTO;
import com.my.mall.manage.order.vo.orderInfo.OrderInfoManageVo;

@Service
public class OrderInfoManageService {
	@Autowired
	OrderInfoManageDao orderInfoManageDao;

	public int selectOrderInfoCount(int orderStatus) {
		if (orderStatus == -1)
			return orderInfoManageDao.selectOrderInfoCount();
		else
			return orderInfoManageDao.selectOrderInfoCountByOrderStatus(orderStatus);
	}

	public List<OrderInfoManageVo> selectOrderInfoList(int orderStatus, int iDisplayStart, int iDisplayLength) {
		if (orderStatus == -1)
			return orderInfoManageDao.selectOrderInfoList(iDisplayStart, iDisplayLength);
		else
			return orderInfoManageDao.selectOrderInfoListByOrderStatus(orderStatus, iDisplayStart, iDisplayLength);
	}

	public int update(OrderInfoManageDTO orderInfo) {
		return orderInfoManageDao.update(orderInfo.getId(), orderInfo.getTotalPrices(), orderInfo.getFreight(),
				orderInfo.getOrderStatus(), orderInfo.getDeliveryDate(), orderInfo.getDeliveryTime());
	}

	public int save(OrderInfoManageDTO orderInfo) {
		return orderInfoManageDao.save(orderInfo.getTotalPrices(), orderInfo.getFreight(), orderInfo.getOrderStatus());
	}

	public OrderInfoManageVo getOrderInfo(int id) {
		return orderInfoManageDao.getOrderInfo(id);
	}

	public int getOrderIdByOrderNumber(String orderNumber) {
		OrderInfoManageVo orderInfo = orderInfoManageDao.getOrderInfoByOrderNumber(orderNumber);
		if (orderInfo != null) {
			return orderInfo.getId();
		}
		return 0;
	}

	public int del(int id) {
		return orderInfoManageDao.del(id);
	}

	public int selectOrderRefundCount(int isRefund) {
		if (isRefund == -1)
			return orderInfoManageDao.selectOrderRefundCount();
		else
			return orderInfoManageDao.selectOrderRefundCountByIsRefund(isRefund);
	}

	public List<OrderInfoManageVo> selectOrderRefundList(int isRefund, int iDisplayStart, int iDisplayLength) {
		if (isRefund == -1)
			return orderInfoManageDao.selectOrderRefundList(iDisplayStart, iDisplayLength);
		else
			return orderInfoManageDao.selectOrderRefundListByIsRefund(isRefund, iDisplayStart, iDisplayLength);
	}

	public int updateByRefund(int id, int isRefund, String refundMessage) {
		return orderInfoManageDao.updateByRefund(id, isRefund, refundMessage);
	}

}